<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Tintucs extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->load->helper("url");
		$this->load->database();
	}
	
	public function getAllTintuc()
	{
		$this->db->order_by('ngay_tintuc','DESC');
		$query = $this->db->get('vtv4_tintuc');
		return $query->result();
	}
	public function getTintuc($id_tintuc)
	{
		$this->db->select('A.*,B.tenthat_nguoidung');
		$this->db->from('vtv4_tintuc A');
		$this->db->join('vtv4_nguoidung B', 'A.id_nguoidung = B.id_nguoidung');
		$this->db->where('id_tintuc',$id_tintuc);
		$query = $this->db->get();
		return $query->row();
	}
	public function getPage($id)
	{
		$this->db->select('A.*,B.tenthat_nguoidung');
		$this->db->from('vtv4_tintuc A');
		$this->db->join('vtv4_nguoidung B', 'A.id_nguoidung = B.id_nguoidung');
		
		$this->db->order_by('ngay_tintuc','DESC');
		$this->db->limit(15,$id);
		$query = $this->db->get();
		return $query->result();
	}
	public function getSoluongTinTuc()
	{
		$this->db->order_by('ngay_tintuc','DESC');
		$query = $this->db->get('vtv4_tintuc');
		return $query->num_rows();
	}
	public function insertTintuc($data)
	{
		return $this->db->insert('vtv4_tintuc',$data);
	}
	public function updateTintuc($data,$id_tintuc)
	{
		$this->db->where('id_tintuc',$id_tintuc);
		return $this->db->update('vtv4_tintuc',$data);
	}
	public function delTintuc($id_tintuc)
	{
		$this->db->where('id_tintuc',$id_tintuc);
		return $this->db->delete('vtv4_tintuc');
	}
}